package com.question.business.menu.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.question.business.menu.entity.Menu;
import com.question.business.menu.model.ao.MenuAO;
import com.question.business.menu.model.ao.MenuDropDownAO;
import com.question.business.menu.model.dto.MenuRouteDTO;
import com.question.business.menu.model.vo.MenuDropDownVO;
import com.question.business.menu.model.vo.MenuRouteVO;
import com.question.business.menu.model.vo.MenuVO;
import com.question.common.annotation.DataConvert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 菜单Mapper接口
 *
 * @author star
 * @since 2023-09-11
 */
@Mapper
public interface MenuMapper extends BaseMapper<Menu> {
    /**
     * 菜单查询
     *
     * @param ao 请求参数
     * @return List<MenuVO> 响应参数
     */
    @DataConvert
    List<MenuVO> queryMenuList(@Param("ao") MenuAO ao);

    /**
     * 菜单下拉列表查询
     *
     * @param ao 请求参数
     * @return List<MenuDropDownVO> 响应参数
     */
    List<MenuDropDownVO> queryMenuDropDown(MenuDropDownAO ao);

    /**
     * 根据角色ID获取菜单代码
     *
     * @param roles 角色
     * @return List<String>
     */
    List<String> queryMenuCodesByRoleId(List<String> roles);

    /**
     * 菜单栏查询
     *
     * @param dto 查询参数
     * @return MenuRouteVO 响应参数
     */
    List<MenuRouteVO> queryMenuRoute(MenuRouteDTO dto);

    /**
     * 获取菜单最新排序
     *
     * @param parentId 上级菜单ID
     * @return int
     */
    @Select("SELECT IFNULL(MAX(m.menu_order),0)+1 AS menuOrder FROM t_menu m WHERE m.is_deleted = 0 AND m.parent_id = #{parentId}")
    int selectMaxOrderByParentId(String parentId);
}